<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>现代部署策略指南 | 灰度发布、金丝雀部署与蓝绿部署</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .first-letter {
            font-size: 3.5em;
            float: left;
            line-height: 0.8;
            margin-right: 0.1em;
            margin-top: 0.1em;
            color: #667eea;
            font-weight: 700;
        }
        .section-title {
            position: relative;
            padding-bottom: 0.5em;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 60px;
            height: 3px;
            background: #667eea;
        }
        .mermaid-container {
            background: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="hero-bg text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <h1 class="text-4xl md:text-5xl lg:text-6xl font-bold mb-6 leading-tight">现代部署策略指南</h1>
                <p class="text-xl md:text-2xl max-w-3xl mx-auto opacity-90">探索灰度发布、金丝雀部署与蓝绿部署的奥秘</p>
                <div class="mt-10">
                    <a href="#strategies" class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-indigo-700 bg-white hover:bg-gray-100 transition duration-300">
                        开始探索 <i class="fas fa-arrow-down ml-2"></i>
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Introduction -->
        <div class="mb-16">
            <p class="text-lg md:text-xl text-gray-700 mb-6">
                <span class="first-letter">灰</span>度发布、金丝雀部署和蓝绿部署是三种常见的发布策略，用于在生产环境中逐步引入新版本，降低风险，并确保系统稳定性。这些策略各有特点，选择合适的部署策略可以有效地降低新版本发布带来的风险，提高系统的稳定性和用户体验。
            </p>
            
            <!-- Visualization -->
            <div class="mermaid-container my-10">
                <div class="mermaid">
                    graph TD
                        A[部署策略] --> B[灰度发布]
                        A --> C[金丝雀部署]
                        A --> D[蓝绿部署]
                        B --> E[逐步发布]
                        B --> F[监控反馈]
                        B --> G[可控回滚]
                        C --> H[小范围测试]
                        C --> I[快速验证]
                        C --> J[矿工比喻]
                        D --> K[双环境]
                        D --> L[零停机]
                        D --> M[即时回滚]
                </div>
            </div>
        </div>

        <!-- Strategies Section -->
        <div id="strategies" class="space-y-20">
            <!-- Gray Release -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="md:flex">
                    <div class="md:w-1/2 p-8 md:p-10">
                        <div class="flex items-center mb-4">
                            <div class="bg-gray-100 rounded-full p-3 mr-4">
                                <i class="fas fa-layer-group text-indigo-600 text-xl"></i>
                            </div>
                            <h2 class="section-title text-2xl md:text-3xl font-bold text-gray-800">灰度发布</h2>
                        </div>
                        <p class="text-gray-700 mb-6">灰度发布是一种逐步发布新版本的方法，通过将新版本逐步推向用户的子集，观察其行为，然后再决定是否全面推广。它的核心在于逐步增加新版本的用户覆盖范围，直到所有用户都迁移到新版本。</p>
                        
                        <h3 class="text-xl font-semibold text-gray-800 mb-3">工作原理</h3>
                        <ul class="space-y-2 text-gray-700 mb-6">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>逐步发布：新版本首先推送到一小部分用户或服务器，然后逐渐扩大范围</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>监控和反馈：在灰度发布过程中，系统会监控新版本的表现，并收集用户反馈</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>扩展和回滚：如果新版本表现良好，发布范围会逐渐扩大；如果出现问题，可以快速回滚到旧版本</span>
                            </li>
                        </ul>
                        
                        <h3 class="text-xl font-semibold text-gray-800 mb-3">适用场景</h3>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="px-3 py-1 bg-indigo-100 text-indigo-800 rounded-full text-sm">系统升级</span>
                            <span class="px-3 py-1 bg-indigo-100 text-indigo-800 rounded-full text-sm">新功能验证</span>
                            <span class="px-3 py-1 bg-indigo-100 text-indigo-800 rounded-full text-sm">风险控制</span>
                        </div>
                    </div>
                    <div class="md:w-1/2 bg-gray-100 flex items-center justify-center p-8">
                        <div class="mermaid">
                            pie
                                title 灰度发布用户分布
                                "新版本用户" : 30
                                "旧版本用户" : 70
                        </div>
                    </div>
                </div>
            </div>

            <!-- Canary Deployment -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="md:flex flex-row-reverse">
                    <div class="md:w-1/2 p-8 md:p-10">
                        <div class="flex items-center mb-4">
                            <div class="bg-yellow-100 rounded-full p-3 mr-4">
                                <i class="fas fa-dove text-yellow-600 text-xl"></i>
                            </div>
                            <h2 class="section-title text-2xl md:text-3xl font-bold text-gray-800">金丝雀部署</h2>
                        </div>
                        <p class="text-gray-700 mb-6">金丝雀部署是一种将新版本应用于一小部分服务器或用户的部署策略，观察其稳定性和性能，然后决定是否全面发布。这个名字来源于早期矿工用金丝雀检测有毒气体的做法，即在发现问题时及时撤离。</p>
                        
                        <h3 class="text-xl font-semibold text-gray-800 mb-3">工作原理</h3>
                        <ul class="space-y-2 text-gray-700 mb-6">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-yellow-500 mt-1 mr-2"></i>
                                <span>初始部署：新版本首先部署到少量服务器（即"金丝雀"服务器）</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-yellow-500 mt-1 mr-2"></i>
                                <span>监控和验证：监控新版本的性能、稳定性和用户反馈</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-yellow-500 mt-1 mr-2"></i>
                                <span>全面部署：如果金丝雀服务器没有问题，新版本会逐步推广到所有服务器</span>
                            </li>
                        </ul>
                        
                        <h3 class="text-xl font-semibold text-gray-800 mb-3">适用场景</h3>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="px-3 py-1 bg-yellow-100 text-yellow-800 rounded-full text-sm">新功能发布</span>
                            <span class="px-3 py-1 bg-yellow-100 text-yellow-800 rounded-full text-sm">减少风险</span>
                            <span class="px-3 py-1 bg-yellow-100 text-yellow-800 rounded-full text-sm">渐进式发布</span>
                        </div>
                    </div>
                    <div class="md:w-1/2 bg-gray-100 flex items-center justify-center p-8">
                        <div class="mermaid">
                            graph LR
                                A[用户流量] --> B[金丝雀服务器]
                                A --> C[稳定服务器集群]
                        </div>
                    </div>
                </div>
            </div>

            <!-- Blue-Green Deployment -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="md:flex">
                    <div class="md:w-1/2 p-8 md:p-10">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 rounded-full p-3 mr-4">
                                <i class="fas fa-sync-alt text-blue-600 text-xl"></i>
                            </div>
                            <h2 class="section-title text-2xl md:text-3xl font-bold text-gray-800">蓝绿部署</h2>
                        </div>
                        <p class="text-gray-700 mb-6">蓝绿部署是一种通过同时运行两个环境（蓝色和绿色）来进行无缝切换的部署策略。新版本会被部署到与当前版本不同的环境中，然后在确认新版本稳定后，切换流量到新环境。</p>
                        
                        <h3 class="text-xl font-semibold text-gray-800 mb-3">工作原理</h3>
                        <ul class="space-y-2 text-gray-700 mb-6">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>环境准备：同时维护两个环境（蓝色和绿色）。当前版本运行在蓝色环境，新版本部署到绿色环境</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>切换流量：当绿色环境准备好后，流量从蓝色环境切换到绿色环境</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>回滚机制：如果新版本出现问题，可以迅速切换回蓝色环境，确保系统的高可用性</span>
                            </li>
                        </ul>
                        
                        <h3 class="text-xl font-semibold text-gray-800 mb-3">适用场景</h3>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm">零停机部署</span>
                            <span class="px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm">全面测试</span>
                            <span class="px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm">回滚需求</span>
                        </div>
                    </div>
                    <div class="md:w-1/2 bg-gray-100 flex items-center justify-center p-8">
                        <div class="mermaid">
                            graph LR
                                U[用户流量] -->|当前| B[蓝色环境]
                                U -->|部署后| G[绿色环境]
                                B -.->|切换| G
                                G -.->|回滚| B
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Comparison Section -->
        <div class="mt-20 bg-white rounded-xl shadow-lg overflow-hidden p-8 md:p-10 card-hover">
            <h2 class="text-2xl md:text-3xl font-bold text-gray-800 mb-8 section-title">策略对比</h2>
            
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">部署策略</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">主要特点</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">优点</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">缺点</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-indigo-600">灰度发布</td>
                            <td class="px-6 py-4">逐步向用户发布新版本</td>
                            <td class="px-6 py-4">风险控制好，可快速回滚</td>
                            <td class="px-6 py-4">部署周期较长</td>
                        </tr>
                        <tr class="bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-yellow-600">金丝雀部署</td>
                            <td class="px-6 py-4">小范围测试后全面发布</td>
                            <td class="px-6 py-4">快速验证，风险可控</td>
                            <td class="px-6 py-4">需要额外监控</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-blue-600">蓝绿部署</td>
                            <td class="px-6 py-4">双环境无缝切换</td>
                            <td class="px-6 py-4">零停机，回滚迅速</td>
                            <td class="px-6 py-4">资源消耗大</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Summary Section -->
        <div class="mt-20">
            <div class="bg-gradient-to-r from-indigo-500 to-blue-600 rounded-xl shadow-lg overflow-hidden p-8 md:p-10 text-white">
                <h2 class="text-2xl md:text-3xl font-bold mb-6">总结</h2>
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <p><span class="font-semibold">灰度发布</span>：适合逐步引入新功能，观察性能和反馈，然后决定是否全面推广。</p>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <p><span class="font-semibold">金丝雀部署</span>：适合在少量服务器上测试新版本，验证其稳定性和性能，再决定是否全面部署。</p>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <p><span class="font-semibold">蓝绿部署</span>：适合需要零停机部署和快速回滚的场景，通过维护两个环境实现无缝切换。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-semibold text-white mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                    http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: { useMaxWidth: true, htmlLabels: true },
            securityLevel: 'loose'
        });
        
        // Add hover effect to cards
        document.querySelectorAll('.card-hover').forEach(card => {
            card.addEventListener('mouseenter', () => {
                card.classList.add('shadow-xl');
            });
            card.addEventListener('mouseleave', () => {
                card.classList.remove('shadow-xl');
            });
        });
    </script>
</body>
</html>